<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/17
 * Time: 16:57
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\business;

use app\common\lib\Show;
use app\common\model\mysql\Enterprise as ModelObj;
use app\common\validate\Enterprise as ValObj;
use think\Exception;

class Enterprise extends Base
{
    protected $valObj = null;
    protected $modelObj = null;

    public function __construct()
    {
        $this->valObj = new ValObj();
        $this->modelObj = new ModelObj();
    }
    public function add(array $data = [])
    {
        try {
            $enterprise = $this->modelObj->getEnterpriseByList();
        }catch (\Exception $e){
            throw new Exception("查询失败");
        }
        try {
            if ($enterprise) {
                $res = $this->modelObj->updateByData($enterprise['id'], $data);
            } else {
                $res = $this->modelObj->save($data);
            }
        }catch (\Exception $e){
            throw new Exception("操作失败");
        }
        return $res;
    }
    public function getEnterpriseByList(){
        try {
            $enterprise = $this->modelObj->getEnterpriseByList();
        }catch (\Exception $e){
            throw new Exception("查询失败");
        }
        if(!$enterprise){
            return '';
        }else{
            return $enterprise['content'];
        }
    }
}